﻿using NHibernate.Mapping.ByCode;
using FinancePortal.Domain.Model;

namespace FinancePortal.Domain.Mapping
{
    public class ResourceMapping : EntityMapping<Resource>
    {
        public ResourceMapping()
        {
            Property(x => x.Email, m =>
                {
                    m.Length(100);
                    m.NotNullable(true);
                });

            Property(x => x.Name, m =>
                {
                    m.Length(100);
                    m.NotNullable(true);
                });

            Property(x => x.SOEID, m =>
                {
                    m.Length(7);
                    m.NotNullable(true);
                });

            Property(x => x.Profile, m =>
                {
                    m.NotNullable(true);
                });

            ManyToOne<Area>(x => x.Area, m =>
                {
                    m.Cascade(Cascade.None);
                    m.NotNullable(true);
                    m.Column("AreaId");
                    m.Insert(false);
                    m.Update(false);
                });

            Property(x => x.AreaId, m =>
            {
                m.NotNullable(true);
                m.Column("AreaId");
            });

            Bag(x => x.ActivitySchedules, c =>
                {
                    c.Key(k =>
                        {
                            k.NotNullable(true);
                            k.Column("ResourceId");
                        });
                    c.Cascade(Cascade.None);
                    //c.Inverse(true);
                    c.Table("ActivityScheduleResource");
                }, r => r.ManyToMany(p => p.Column("ActivityScheduleId")));
        }
    }
}
